package KaoShi01;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Test18 {
    public static void main(String[] args) {

        //创建集合
        ArrayList<Student> list = new ArrayList<>();
        //创建学生对象
        Student stu1 = new Student("张三",1,98);
        Student stu2 = new Student("李四",2,86);
        Student stu3 = new Student("王五",3,90);
        Student stu4 = new Student("赵六",4,89);
        Student stu5 = new Student("麻七",5,76);
        //添加
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        list.add(stu4);
        list.add(stu5);
        //排序
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getScore() - o1.getScore();
            }
        });
        System.out.println(list);
        //遍历
        for (Student student : list) {
            System.out.println(student);
        }
        //删除前三名以后的学生
        list.remove(3);
        list.remove(3);
        //打印前三名信息
        System.out.println(list);
    }
}
